package com.test;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

public class test8 {

    //内存可见性（工作内存和主内存同步） 禁用指令重排
    volatile static int count=0;
    //原子操作
    static AtomicInteger atomicInteger=new AtomicInteger(0);

    public static void main(String[] args) throws InterruptedException {
        ExecutorService theadPool= Executors.newFixedThreadPool(1000);

        for (int i=1;i<=1000;i++){
            theadPool.execute(new Runnable() {
                @Override
                public void run() {
                    count=atomicInteger.incrementAndGet();
                }
            });
        }
        theadPool.shutdown();
        theadPool.awaitTermination(1, TimeUnit.MINUTES);  //如果一分钟还没执行完所有线程则退出
        System.out.println(count);
    }

}
